<?
if (!defined('SMF'))
	die('Hacking attempt...');

global $smcFunc, $txt, $scripturl;
global $dbtables;

// Verify user login, if CheckLogin() returns false return to the calling script/function
if (CheckLogin() == false)
	return;	

$result = $smcFunc['db_query']('', '
	SELECT COUNT(*) AS loggedin
	FROM {raw:db_ships}
	WHERE (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(last_login)) < 300
	AND xenobe = "N"',
	array(
		'db_ships' => $dbtables['ships']
	)
);
$row = $smcFunc['db_fetch_assoc']($result);
$online = $row['loggedin'];
$smcFunc['db_free_result']($result);

$result = $smcFunc['db_query']('', '
	SELECT next_run
	FROM {raw:db_scheduler}
	LIMIT 1',
	array(
		'db_scheduler' => $dbtables['scheduler']
	)
);
$row = $smcFunc['db_fetch_assoc']($result);
$sec_until_update = $row['next_run'] - time();
$smcFunc['db_free_result']($result);

echo '
									<div id="bnt_update">
										<ul class="rounded_left">
											<li class="bnt_menuheader">', $txt['bnt_footer_next_update'], '</li>';
if ($sec_until_update > 0)
{
	echo '
											<li class="bnt_staticmenu"><span id="update_frame"><span id="bnt_timer">', $sec_until_update, '</span> ', $txt['bnt_footer_seconds'], '</span></li>';
}
else
{
	echo '
											<li class="bnt_staticmenu"><span id="bnt_timer">Updating</span></li>';
}

echo '
											</ul>
									</div>
									<div id="bnt_online">
										<ul class="rounded_left">
											<li class="bnt_menuheader">', $txt['bnt_footer_players'], '</li>
											<li class="bnt_staticmenu"><a id="menu_online_ranking" href="#" title="sa=ranking">', $online, '</a></li>
										</ul>
									</div>
									<script language="javascript" type="text/javascript">
										$(".rounded_left").corners("top-left bottom-left transparent no-native");
										sec_until_update = ', $sec_until_update, '
										setTimeout("TimerUpdate();",1000);
										
										TimerUpdate = function ()
										{
											sec_until_update = sec_until_update - 1;
											
											if (sec_until_update < 1)
											{
												$("#update_frame").html("Updating");
												$("#update_frame").effect("pulsate", {}, 1000);
												$("#bnt_footer").load(smf_prepareScriptUrl(smf_scripturl) + "action=blacknova;sa=scheduler;xml", function() {
													$("#turns_available").html($("#scheduler_turns_available").val());
												});
												return;
											}
											else
											{
												document.getElementById("bnt_timer").innerHTML = sec_until_update;
											}
											
											setTimeout("TimerUpdate();",1000);
										}
									</script>';
?>